package com.siants.pageprocesser;

import com.siants.common.pipeline.CommonPipeline;
import com.siants.downloader.ShiroDownLoader;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.downloader.HttpClientDownloader;
import us.codecraft.webmagic.pipeline.ConsolePipeline;
import us.codecraft.webmagic.pipeline.FilePipeline;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.scheduler.FileCacheQueueScheduler;

import java.util.List;

/**
 * Created by yanxin on 2016/9/13.
 */
public class ShiroPageProcesser implements PageProcessor {
    private Site site = Site.me().setDomain("shiro.apache.org")
            .addStartUrl("http://shiro.apache.org/reference");
    public void process(Page page) {
        List<String> links = page.getHtml().$("#content").links().all();
        page.addTargetRequests(links);
        page.putField("title", page.getHtml().xpath("//title").toString());
        page.putField("content", page.getHtml().$("#content").toString());
    }

    public Site getSite() {
        return site;
    }

    public static void main(String[] args) {
        Spider.create(new ShiroPageProcesser())
                .addPipeline(new CommonPipeline("D:\\test\\"))
                .thread(5).run();
    }
}
